package com.ruoyi.course.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.course.domain.CourseGate;
import com.ruoyi.course.service.ICourseGateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 出勤管理Controller
 * 
 * @author UtadaCCC
 * @date 2025-06-18
 */
@RestController
@RequestMapping("/course/courseGate")
public class CourseGateController extends BaseController
{
    @Autowired
    private ICourseGateService courseGateService;

    /**
     * 查询出勤管理列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseGate:list')")
    @GetMapping("/list")
    public TableDataInfo list(CourseGate courseGate)
    {
        startPage();
        List<CourseGate> list = courseGateService.selectCourseGateList(courseGate);
        return getDataTable(list);
    }

    /**
     * 导出出勤管理列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseGate:export')")
    @Log(title = "出勤管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseGate courseGate)
    {
        List<CourseGate> list = courseGateService.selectCourseGateList(courseGate);
        ExcelUtil<CourseGate> util = new ExcelUtil<CourseGate>(CourseGate.class);
        util.exportExcel(response, list, "出勤管理数据");
    }

    /**
     * 获取出勤管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:courseGate:query')")
    @GetMapping(value = "/{gateId}")
    public AjaxResult getInfo(@PathVariable("gateId") Integer gateId)
    {
        return success(courseGateService.selectCourseGateByGateId(gateId));
    }

    /**
     * 新增出勤管理
     */
    @PreAuthorize("@ss.hasPermi('course:courseGate:add')")
    @Log(title = "出勤管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseGate courseGate)
    {
        return toAjax(courseGateService.insertCourseGate(courseGate));
    }

    /**
     * 修改出勤管理
     */
    @PreAuthorize("@ss.hasPermi('course:courseGate:edit')")
    @Log(title = "出勤管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseGate courseGate)
    {
        return toAjax(courseGateService.updateCourseGate(courseGate));
    }

    /**
     * 删除出勤管理
     */
    @PreAuthorize("@ss.hasPermi('course:courseGate:remove')")
    @Log(title = "出勤管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gateIds}")
    public AjaxResult remove(@PathVariable Integer[] gateIds)
    {
        return toAjax(courseGateService.deleteCourseGateByGateIds(gateIds));
    }
}
